package cn.dg.manager;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import cn.dg.connect.C3P0Utils;
import cn.dg.connect.poolmanager;
import cn.dg.helper.StringHelper;

public class T_ACL_User_manager {

	public boolean isExists(String user, String pwd) {
		poolmanager dbcon = new poolmanager();
		StringBuilder sb = new StringBuilder();
		sb.append("select * from t_acl_user where UserID ='");
		sb.append(StringHelper.convertStringNull(user));
		sb.append("' and pwd='" + pwd + "'");
		try {
			ResultSet rs = dbcon.executeQuery(sb.toString());

			int rowCount = 0;
			rs.last();
			rowCount = rs.getRow();
			dbcon.freeConnection();
			if (rowCount == 0)
				return false;
			else
				return true;
		} catch (Exception e) {
			e.printStackTrace();
			dbcon.freeConnection();
			return false;
		}
	}

	@SuppressWarnings("finally")
	public boolean isExists_CSP0(String user, String pwd) {
		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;
		int rowCount = 0;
		StringBuilder sb = new StringBuilder();
		sb.append("select * from t_acl_user where UserID ='");
		sb.append(StringHelper.convertStringNull(user));
		sb.append("' and pwd='" + pwd + "'");

		try {
			conn = (Connection) C3P0Utils.getConnection();
			System.out.println(conn);
			stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
					ResultSet.CONCUR_UPDATABLE);
			rs = stmt.executeQuery(sb.toString());

			rs.last();
			rowCount = rs.getRow();
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (final Exception e) {
				}
			}

			if (stmt != null) {
				try {
					stmt.close();
				} catch (final Exception e) {
				}
			}

			if (conn != null) {
				try {
					conn.close();
				} catch (final Exception e) {
				}
			}
			C3P0Utils.closeConnection();

			if (rowCount == 0)
				return false;
			else
				return true;
		}

	}

	public static boolean isExiststest(String user, String pwd) {
		System.out.println(user + "++++++" + "pwd");
		if ("111".equals(user) && "111".equals(pwd))
			return true;
		else
			return false;
	}
}
